package com.qidianit.mes.pro.controller;

import com.github.pagehelper.PageInfo;
import com.qidianit.mes.pojo.Result;
import com.qidianit.mes.pojo.pro.WorkflowProcess;
import com.qidianit.mes.pro.service.WorkflowProcessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: YKYB
 * @Date: 2025/9/18 21:40
 * @Description:
 */

@RestController
@RequestMapping("workflowProcess")
public class WorkFlowProcessController {
    @Autowired
    private WorkflowProcessService workflowProcessService;

    /**
     * 根据工艺id分页查询工序组成
     */
    @GetMapping("/page")
    public Result<PageInfo<WorkflowProcess>> page(@RequestParam(required = false) Long workflowId,
                                                  @RequestParam(defaultValue = "1") Integer page,
                                                  @RequestParam(defaultValue = "10") Integer size) {
        return workflowProcessService.selectList(workflowId, page, size);
    }

    /**
     * 新增工序组成
     */
    @PostMapping("/add")
    public Result<WorkflowProcess> add(@RequestBody WorkflowProcess wp) {
        return workflowProcessService.add(wp);
    }

    /**
     * 根据id查询工艺工序组成
     */
    @GetMapping("/{id}")
    public Result<WorkflowProcess> getById(@PathVariable Long id) {
        return workflowProcessService.selectById(id);
    }

    /**
     * 编辑工序组成
     */
    @PutMapping("/update")
    public Result<WorkflowProcess> update(@RequestBody WorkflowProcess wp) {
        return workflowProcessService.update(wp);
    }

    @DeleteMapping("/delete/{id}")
    public Result<?> delete(@PathVariable Long id) {
        return workflowProcessService.deleteById(id);
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/batchDelete")
    public Result<?> batchDelete(@RequestParam("id") List<Long> id) {
        return workflowProcessService.batchDelete(id);
    }

}
